package com.grass.p019lv.novel.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.bean.novel.SearchNovelHotRecommendBean;
import com.androidx.p013lv.base.dialog.BuyVipDialog;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.grass.p019lv.OnClickListenType;
import com.grass.p019lv.bean.AudioRecommendBean;
import com.grass.p019lv.bean.VioceNovelChangeBean;
import com.grass.p019lv.databinding.FragmentClassFictionABinding;
import com.grass.p019lv.novel.activity.SearchNovelActivity;
import com.grass.p019lv.novel.activity.VoiceNovelActivityNew;
import com.grass.p019lv.novel.adapter.AudioFictionAAdapterType;
import com.grass.p019lv.novel.adapter.AudioFictionTwoViewAdapter;

/* renamed from: com.grass.lv.novel.fragment.AudioFictionAFragment */
public class AudioFictionAFragment extends LazyFragment<FragmentClassFictionABinding> implements ItemClickListener, OnClickListenType {
    AudioFictionAAdapterType adapter;
    AudioFictionTwoViewAdapter adapterTwo;

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_class_fiction_a;
    }

    public static AudioFictionAFragment newInstance(int i) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("data", Integer.valueOf(i));
        AudioFictionAFragment audioFictionAFragment = new AudioFictionAFragment();
        audioFictionAFragment.setArguments(bundle);
        return audioFictionAFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        ((FragmentClassFictionABinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        this.adapter = new AudioFictionAAdapterType(this);
        ((FragmentClassFictionABinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.setItemListener(this);
        ((FragmentClassFictionABinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.grass.p019lv.novel.fragment.AudioFictionAFragment.View$OnClickListenerC31591 */

            public void onClick(View view) {
                AudioFictionAFragment.this.getInfo();
            }
        });
        initViewTwo();
    }

    private void initViewTwo() {
        final View findViewById = getView().findViewById(R.id.include_ranking_layout);
        ((FragmentClassFictionABinding) this.binding).includeRankingLayout.recycler.setLayoutManager(new GridLayoutManager((Context) getActivity(), 5, 0, false));
        this.adapterTwo = new AudioFictionTwoViewAdapter();
        ((FragmentClassFictionABinding) this.binding).includeRankingLayout.recycler.setAdapter(this.adapterTwo);
        this.adapterTwo.setItemListener(new ItemClickListener() {
            /* class com.grass.p019lv.novel.fragment.AudioFictionAFragment.C31602 */

            @Override // com.androidx.p013lv.base.listener.ItemClickListener
            public void onItemClick(View view, int i) {
                if (!AudioFictionAFragment.this.isOnClick()) {
                    if (SpUtils.getInstance().getUserInfo().getFreeWatches() != -1) {
                        new BuyVipDialog(AudioFictionAFragment.this.getContext()).show();
                        return;
                    }
                    int fictionId = ((SearchNovelHotRecommendBean.SearchNovelHotRecommendData) AudioFictionAFragment.this.adapterTwo.getDataInPosition(i)).getFictionId();
                    Intent intent = new Intent(AudioFictionAFragment.this.getActivity(), VoiceNovelActivityNew.class);
                    intent.putExtra(Key.NOVEL_ID, fictionId);
                    AudioFictionAFragment.this.getActivity().startActivity(intent);
                }
            }
        });
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getNovelHotSearch(2, 10), new HttpCallback<BaseRes<SearchNovelHotRecommendBean>>("queryHotSearch") {
            /* class com.grass.p019lv.novel.fragment.AudioFictionAFragment.C31613 */

            public void onLvSuccess(BaseRes<SearchNovelHotRecommendBean> baseRes) {
                if (baseRes.getCode() != 200) {
                    Log.e("...", "出错");
                } else if (baseRes.getData() != null && baseRes.getData().getData() != null && baseRes.getData().getData().size() > 0) {
                    findViewById.setVisibility(0);
                    AudioFictionAFragment.this.adapterTwo.setData(baseRes.getData().getData());
                }
            }
        });
        ((FragmentClassFictionABinding) this.binding).includeRankingLayout.tvSeeMore.setOnClickListener(new View.OnClickListener() {
            /* class com.grass.p019lv.novel.fragment.AudioFictionAFragment.View$OnClickListenerC31624 */

            public void onClick(View view) {
                Intent intent = new Intent(AudioFictionAFragment.this.getActivity(), SearchNovelActivity.class);
                intent.putExtra("page", 1);
                AudioFictionAFragment.this.getActivity().startActivity(intent);
            }
        });
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void onFirstUserVisible() {
        super.onFirstUserVisible();
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (!NetUtil.isNetworkAvailable()) {
            ((FragmentClassFictionABinding) this.binding).statusLayout.showNoNet();
            return;
        }
        ((FragmentClassFictionABinding) this.binding).statusLayout.showLoading();
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getAudioFictionList(), new HttpCallback<BaseRes<AudioRecommendBean>>("getAudioFictionList") {
            /* class com.grass.p019lv.novel.fragment.AudioFictionAFragment.C31635 */

            public void onLvSuccess(BaseRes<AudioRecommendBean> baseRes) {
                ((FragmentClassFictionABinding) AudioFictionAFragment.this.binding).statusLayout.hideLoading();
                if (baseRes.getCode() != 200) {
                    ((FragmentClassFictionABinding) AudioFictionAFragment.this.binding).statusLayout.showError();
                } else if (baseRes.getData() == null || baseRes.getData().getData() == null || baseRes.getData().getData().size() <= 0) {
                    ((FragmentClassFictionABinding) AudioFictionAFragment.this.binding).statusLayout.showEmpty();
                } else {
                    AudioFictionAFragment.this.adapter.setDomain(baseRes.getData().getDomain());
                    AudioFictionAFragment.this.adapter.setData(baseRes.getData().getData());
                }
            }
        });
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onResume() {
        super.onResume();
        getUserInfo();
    }

    public void getUserInfo() {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().userInfo(), JsonParams.build().commit(), new HttpCallback<BaseRes<UserInfo>>("userInfo") {
            /* class com.grass.p019lv.novel.fragment.AudioFictionAFragment.C31646 */

            public void onLvSuccess(BaseRes<UserInfo> baseRes) {
                if (baseRes.getCode() == 200) {
                    SpUtils.getInstance().setUserInfo(baseRes.getData());
                }
            }
        });
    }

    @Override // com.grass.p019lv.OnClickListenType
    public void onClick(AudioRecommendBean.AudioRecommendBeanData audioRecommendBeanData, int i, int i2) {
        if (i2 == R.id.tv_audio_changeBatch && !isOnClick()) {
            setChangeData(audioRecommendBeanData, i);
        }
    }

    private void setChangeData(AudioRecommendBean.AudioRecommendBeanData audioRecommendBeanData, final int i) {
        if (audioRecommendBeanData.getFictionBaseList() != null && audioRecommendBeanData.getFictionBaseList().size() != 0) {
            HttpUtils.getInsatance().get(UrlManager.getInsatance().changeStationFiction(audioRecommendBeanData.getStationId(), audioRecommendBeanData.getFictionBaseList().get(0).getFictionId(), 6), new HttpCallback<BaseRes<VioceNovelChangeBean>>("changeStationFiction") {
                /* class com.grass.p019lv.novel.fragment.AudioFictionAFragment.C31657 */

                public void onLvSuccess(BaseRes<VioceNovelChangeBean> baseRes) {
                    ((FragmentClassFictionABinding) AudioFictionAFragment.this.binding).statusLayout.hideLoading();
                    if (baseRes.getCode() == 200) {
                        ((AudioRecommendBean.AudioRecommendBeanData) AudioFictionAFragment.this.adapter.getDataInPosition(i)).setFictionBaseList(baseRes.getData().getData());
                        AudioFictionAFragment.this.adapter.notifyItemChanged(i);
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            });
        }
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag("getAudioFictionList");
        HttpUtils.getInsatance().cancelTag("changeStationFiction");
    }
}
